import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class JDBCDemo3 {
    public static void main(String[] args) throws SQLException {
        //创建数据源
        DataSource dataSource = new MysqlDataSource();
        ((MysqlDataSource) dataSource).setUrl("jdbc:mysql://127.0.0.1:3306/java113?characterEncoding=utf8&useSSL=false");
        ((MysqlDataSource) dataSource).setUser("root");
        ((MysqlDataSource) dataSource).setPassword("665181");


        //建立连接
        Connection connection = dataSource.getConnection();


        //构造sql
        String sql = "delete from test where name = '李四' ";
        PreparedStatement statement = connection.prepareStatement(sql);

        // 执行sql
        int n = statement.executeUpdate();
        System.out.println("n = " + n);
        //释放资源
        statement.close();
        connection.close();
    }
}
